var EventUtil = {
    addHandler: function(element,type,handler) {
        if(element.addEventListener) {
            element.addEventListener(type,handler,false);
        }else if(element.attachEvent) {
            element.attachEvent("on"+type,handler);
        }else {
            element["on" +type] = handler;
        }
    },
    removeHandler: function(element,type,handler){
        if(element.removeEventListener) {
            element.removeEventListener(type,handler,false);
        }else if(element.detachEvent) {
            element.detachEvent("on"+type,handler);
        }else {
            element["on" +type] = null;
        }
    }
};
//require("ww.ashlybus.com/m/other/tpl.html");
$(function(){
    var href=window.location.href.split("com")[0]+"com";
    $.ajax({
        type:"GET",
        url:href+"/m/other/tpl.html",
        success:function(data, textStatus, jqXHR){
            $("body").append(data);
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
            console.log(XMLHttpRequest, textStatus, errorThrown);
        }
    });
    if((document.getElementById("search")!==null)&&!(document.getElementById("searchCar"))){
        var search = new Vue({
            el: '#search',
            data: {
                cartype:{},
                picked:'全部'
            },
            methods:{
                getData_:function(){
                    var _self=this;
                    $.ajax({
                        type:"GET",
                        url:href+"/m/data/cartype.php",
                        success:function(data, textStatus, jqXHR){
                            var obj={"tupe_id":"all","type_name":"全部"};
                            _self.cartype=data;
                            _self.cartype.unshift(obj);
                        },
                        error:function(XMLHttpRequest, textStatus, errorThrown){
                            console.log(XMLHttpRequest, textStatus, errorThrown);
                        }
                    })
                },
                searchHref:function(e){
                    //var type_name=$.trim($(".select_text").html());
                    //var type_id="all";
                    //if(!isNaN(parseInt(type_name))){
                    //    type_id=$(":radio:checked").attr("type_id");
                    //}
                    //window.location.href=href+"/m/other/search.html?type_id="+type_id;
                    var elem=e.target;
                    if(elem.nodeName=="LABEL"){
                        console.log(111);
                        elem=elem.firstElementChild;
                        type_id=elem.getAttribute("type_id");
                        console.log(elem,type_id);

                    }else if(elem.nodeName=="input"){
                        console.log(222);
                        type_id=elem.getAttribute("type_id");
                        console.log(type_id);
                    }
                    window.location.href=href+"/m/other/search.html?type_id="+type_id;
                },
                selectClick:function(){
                    $(".popup_box").fadeIn();
                },
                colseClick:function(){
                    $(".popup_box").fadeOut();
                },
                selected:function(e){
                    console.log(e);
                    var elem=e.target;
                    if(elem.nodeName=="LABEL"){
                        console.log(111);
                        elem=elem.firstElementChild;
                        var type_id=elem.getAttribute("type_id");
                        console.log(elem,type_id);

                    }else if(elem.nodeName=="input"){
                        console.log(222);
                        var type_id=elem.getAttribute("type_id");
                        console.log(type_id);
                    }


                    $(":radio:checked").parent().addClass("inputS")
                        .siblings().removeClass("inputS");
                    //this.searchHref();
                }
            }
        });
        search.getData_();
        $(".popup_box").on("touchend",function(e){
            if(e.target.className=="popup_box"){
                if(e.target.className=="box"){
                    return 0;
                }else{
                    $(this).fadeOut();
                }
            }
        });
    }
});


